﻿using AutoMapper;
using MediatR;
using Traceability.App.Api.Application.Command.Get;
using Traceability.App.Api.DTO;
using Traceability.App.Domain;
using Traceability.App.ErrorCode;
using Traceability.App.Instructure;

namespace Traceability.App.Api.Application.Handler.Get
{
    public class GetAquacultureHandler : IRequestHandler<GetAquacultureCommand, ApiResult<Aquaculture>>
    {
        private readonly IBaseRepository<Aquaculture> aquacultureRepo;
       

        public GetAquacultureHandler(IBaseRepository<Aquaculture> aquacultureRepo) 
        {
            this.aquacultureRepo = aquacultureRepo;
           
        }
        public Task<ApiResult<Aquaculture>> Handle(GetAquacultureCommand request, CancellationToken cancellationToken)
        {
            ApiResult<Aquaculture> res = new ApiResult<Aquaculture>();
            var aquaculture = aquacultureRepo.GetAll().Where(x => x.Batch == request.Batch).FirstOrDefault();
            res.Code = ApiEnum.Success;
            res.Data = aquaculture;
            res.Msg = "显示成功";
            return Task.FromResult(res);
        }
    }
}
